package com.heima.controller;
import com.heima.pojo.dto.PageQueryDTO;
import com.heima.pojo.dto.PartnerDTO;
import com.heima.pojo.vo.PartnerQueryVO;
import com.heima.pojo.vo.PartnerVO;
import com.heima.result.PageResult;
import com.heima.service.PartnerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/user-service/partner")
public class PartnerController {
    /**
     * 合作商管理接口
     */
    @Autowired
    PartnerService partnerService;

    /**
     * 合作商新增接口
     *
     * @param dto
     * @return
     */
    @PostMapping
    public boolean insert(@RequestBody PartnerDTO dto) {
        boolean result = partnerService.insert(dto);
        return result;
    }

    /**
     * 合作商查询接口
     */
    @GetMapping("/search")
    public PageResult<PartnerQueryVO> page(PageQueryDTO dto) {
        PageResult<PartnerQueryVO> page = partnerService.page(dto);
        return page;
    }

    /**
     * 根据id获取
     */
    @GetMapping("/{id}")
    public PartnerVO selectById(@PathVariable Integer id) {
        PartnerVO vo = partnerService.selectById(id);
        return vo;
    }

    /**
     * 修改合作商信息
     */
    @PutMapping("/{id}")
    public boolean put(@PathVariable("id") Integer id, @RequestBody PartnerDTO dtoa) {
        boolean result = partnerService.update(id, dtoa);
        return result;
    }

    /**
     * 删除供应商
     */
    @DeleteMapping("/{id}")
    public boolean del(@PathVariable Integer id) {
        boolean result = partnerService.del(id);
        return result;
    }
}
